package com.company.server;

import com.company.common.Message;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.time.LocalDateTime;
import java.util.Scanner;

public class MessagePushThd implements Runnable {
    @Override
    public void run() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入要推送的消息(exit退出)：");
            String msg = scanner.next();
            if ("exit".equals(msg)) break;
            for (String key : ConnCliThdManage.getKeys()) {
                Message<String> message = new Message<>(msg, Message.MessageType.GROUP_MSG, "", "服务器", LocalDateTime.now());
                try {
                    new ObjectOutputStream(ConnCliThdManage.get(key).getSocket().getOutputStream()).writeObject(message);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
